<?php
/**
 * Created by PhpStorm.
 * User: MrHung
 * Date: 1/13/14
 * Time: 4:52 PM
 */

namespace Admin\Controller;

use Zend\Mail;
use Zend\Mime\Part as MimePart;
use Zend\Mime\Message as MimeMessage;

class EmailController {

    protected $option;
    protected $email_template;
    protected $render;

    function indexAction(){

    }
    function config(){
        // setup SMTP options
        $this->option = new Mail\Transport\SmtpOptions(array(
            'name' => 'localhost',
            'host' => 'smtp.gmail.com',
            'port'=> 587,
            'connection_class' => 'login',
            'connection_config' => array(
                'username' => 'mrhungmaster1905@gmail.com',
                'password' => '`1qa2ws#ED',
                'ssl'=> 'tls',
            ),
        ));
        return $this->option;
    }
    function SendViaGmail(){

        $this->email_template = $email_template;
        $this->renderer = $this->getServiceLocator()->get('ViewRenderer');
        $content = $this->renderer->render('admin/email/tpl/template', null);

        // make a header as html
        $html = new MimePart($content);
        $html->type = "text/html";
        $body = new MimeMessage();
        $body->setParts(array($html,));

        // instance mail
        $mail = new Mail\Message();
        $mail->setBody($body); // will generate our code html from template.phtml
        $mail->setFrom('sender email address','Sender Name');
        $mail->setTo('some email addressed');
        $mail->setSubject('Your Subject');

        $transport = new Mail\Transport\Smtp($options);
        $transport->send($mail);

    }
} 